package it.desertsupport.hibernate.dao;

import it.desertsupport.model.Army;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

public class ArmyDAOImpl extends BaseHibernateDAO implements ArmyDAO {

	@Override
	public void save(Army army) throws Exception {
		getSession().save(army);
	}

	@Override
	public void delete(Army army) throws Exception {
		getSession().delete(army);
	}

	@Override
	public Army getArmy(Long id) throws Exception {
		return (Army) getSession().get(Army.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Army> findAll() throws Exception {
		String queryString = "from Army";
		Query queryObject = getSession().createQuery(queryString);
		return queryObject.list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Army> findByExample(Army army) throws Exception {
		Criteria cri = getSession().createCriteria(Army.class);
		cri.add(Example.create(army));
		return cri.list();
	}

	@Override
	public Army marge(Army army) throws Exception {
		return (Army) getSession().merge(army);
	}

}
